"""the graph input in topological sorted
first node is u, last node is v
count number of paths from u to v"""
def count_path_u_v(Adj):
    tbl=[0]*(len(Adj))
    tbl[0]=1 #tbl[0]用作初值
    for i in range(len(Adj)):
        for j in Adj[i]:
            tbl[j]=tbl[j]+tbl[i]
    return tbl[-1]

if __name__=='__main__':
    Adj=[[1,1,2,2],[2,2,2,3,3],[3],[]]
    print count_path_u_v(Adj)
